package com.aurora.color.adapter;

import static android.graphics.Color.parseColor;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.cardview.widget.CardView;

import com.aurora.color.R;


/**
 * 子颜色列表适配器
 */
public class ZiListAdapter extends BaseAdapter {

    private String[] zColor;    //子颜色数组
    private Context context;    //上下文内容

    //子颜色的名称
    private final String[] po = {"50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "A100", "A200", "A400", "A700"};


    public ZiListAdapter(String[] zColor, Context context) {
        this.zColor = zColor;
        this.context = context;
    }

    @Override
    public int getCount() {
        return zColor.length;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint({"ViewHolder", "InflateParams", "ResourceAsColor"})
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        //获取裂列表项控件
        view = LayoutInflater.from(context).inflate(R.layout.item_list_detail, null);
        CardView card_bg = view.findViewById(R.id.item_ld_card);
        TextView tv_name = view.findViewById(R.id.item_ld_name);
        TextView tv_code = view.findViewById(R.id.item_ld_code);


        //文字颜色
        String tc_sign = zColor[i].substring(0, 1);
        int white = context.getColor(R.color.white);
        int black = context.getColor(R.color.black);
        if ("F".equals(tc_sign)) {
            tv_name.setTextColor(white);
            tv_code.setTextColor(white);
        } else if ("0".equals(tc_sign)) {
            tv_name.setTextColor(black);
            tv_code.setTextColor(black);
        }

        //颜色名称
        String name = po[i];
        tv_name.setText(name);

        //颜色代码
        String code = zColor[i].substring(1);
        tv_code.setText(code);

        int color = parseColor(code);
        card_bg.setCardBackgroundColor(color);

        return view;
    }


}
